package Operation;

import Books.Book;
import Books.Booklist;

import java.util.Scanner;

public class Delebook extends Booklist implements IOPeration{
    @Override
    public void work(Booklist booklist) {
        System.out.println("删除图书");
        System.out.println("请输入要删除的图书名称");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int uersszie=booklist.getUsersize();
        int temp=-1;
        for(int i=0;i<uersszie;i++){
            Book book=booklist.getbook(i);
            if(book.getBname().equals(name)){
                    temp=i;
                    break;
            }
        }
        for (int i=temp;i<uersszie-1;i++){
            Book arr=booklist.getbook(i+1);
            booklist.setbook(i,arr);
           booklist.setbook(uersszie,null);
        }
        booklist.setUsersize(uersszie-1);
    }
}
